package com.francis.demo.action;

import com.francis.demo.service.IQueryService;
import com.francis.spring.framework.annotation.FrancisAutowired;
import com.francis.spring.framework.annotation.FrancisController;
import com.francis.spring.framework.annotation.FrancisRequestMapping;
import com.francis.spring.framework.annotation.FrancisRequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Francis
 * @Date 2020/11/15 18:35
 * @Version 1.0
 * @Description:
 */
@FrancisController
@FrancisRequestMapping("/francis")
public class FrancisAction {






    @FrancisAutowired
    IQueryService queryService;

    @FrancisRequestMapping("/query.json")
    public void query(HttpServletRequest request, HttpServletResponse response,
                      @FrancisRequestParam("name") String name){
        String result = queryService.query(name);
        out(response,result);
    }
    @FrancisRequestMapping("/ex.json")
    public void queryEx(HttpServletRequest request, HttpServletResponse response,
                      @FrancisRequestParam("name") String name) throws Exception {
        queryService.thorws(name);
        out(response,"");
    }
    private void out(HttpServletResponse resp,String str){
        try {
            resp.getWriter().write(str);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
